//
//  CommentView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/9.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "CommentView.h"

@interface CommentView()
{
    void (^callback)(NSString *comment);
    
    UITextView *textV;
    UIButton *replyBtn;
    UIImageView *bgImg;
    
}
@end

@implementation CommentView

-(instancetype)initWithReply:(void (^)(NSString *))block
{
    self = [super initWithFrame:CGRectMake(0, 0, IPHONEWIDTH, TabbarHeight+13)];
    
    if (self) {
        callback = block;
        
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    //背景虚化
    UIBlurEffectStyle style = UIBlurEffectStyleLight;
    if (@available(iOS 9.0,*)) {
        style = UIBlurEffectStyleProminent;
    }
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:style];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 0, self.width, self.height);
    [self addSubview:effectView];
    
    replyBtn = [UIButton makeButton:^(TTButtonExtend *make) {
        make.addTitleColor(UIColorFromRGB(0x744A05),UIControlStateNormal).addFont([UIFont systemFontOfSize:13.0f]);
        make.addBackGoundColor(FBEE_COLOR_ASSISTANT);
        make.addTitle(NSLocalizedString(@"mReply", nil));
        make.setFrame(CGRectMake(0, 13, 70, 40));
        make.right = IPHONEWIDTH - 16;
        make.layer.cornerRadius = 20;
        make.addTarget(self,@selector(onClick));
        [self addSubview:make];
    }];
    
    bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(16, 13, replyBtn.left - 16 - 4, 40)];
    bgImg.backgroundColor = COLOR_WHITE;
    bgImg.layer.cornerRadius = 20;
    bgImg.layer.borderColor = UIColorFromRGB(0xEDEDED).CGColor;
    bgImg.layer.borderWidth = 1;
    [self addSubview:bgImg];
    
    textV = [[UITextView alloc] initWithFrame:CGRectMake(bgImg.left + 10, 13, bgImg.width - 20, 40)];
    textV.tintColor = FBEE_COLOR_ASSISTANT;
    textV.font = [UIFont systemFontOfSize:16.0f];
    textV.backgroundColor = [UIColor clearColor];
    [self addSubview:textV];
    
}

-(void)resignFirstResponder
{
    [textV resignFirstResponder];
}

-(void)clearText
{
    [textV setText:@""];
}

-(void)onClick
{
    [textV resignFirstResponder];
    
    if (callback) {
        callback(textV.text);
    }
}


@end
